package servlet;

import mapper.StudentMapper;
import utils.MybatisUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author leiHua
 * @Date 2022/11/24 18:57
 */
@WebServlet("/deleteStudentServlet")
public class DeleteStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String num = request.getParameter("num");
        StudentMapper mapper = MybatisUtils.getSqlSession().getMapper(StudentMapper.class);
        int i = mapper.deleteStudentByNum(num);
        if (i>0){
            response.sendRedirect("ShowAllStudentsServlet");
        }else {
            response.getWriter().write("删除失败");
        }

    }
}
